<table data-options="fit:true" id="admin_manager"></table>

<script>
	$(function(){ 
		var datagrid; 
		datagrid=$('#admin_manager').datagrid({   
		    url:'../adminServlet',
		    queryParams:{op:"getAllAdmin"},
		    loadMsg:'数据加载中...',
		    pagination:true,
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'aid',
		    columns:[[
		    	{field:'aids',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'aid',title:'编号',width:100,align:'center'},   
		        {field:'aname',title:'账号',width:100,align:'center'},
		        {field:'apwd',title:'密码',width:100,align:'center'},
		        {field:'astatuss',title:'状态',width:100,align:'center'}    
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					$("#add_admin").dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
						//获取选中的行
					var rows=datagrid.datagrid("getChecked");
					if(rows.length==0){
						$.messager.alert('错误提示','请选择您要删除的文章...','error');
					}else{
						//获取到行中的id
						var aid="";
						//如果有多个
						if(rows.length>1){
							for(var i=0;i<rows.length-1;i++){
								aid+=rows[i].aid+",";
							}
							aid+=rows[i].aid;
						}else{
							aid=rows[0].aid;
						}
						$.post("../adminServlet",{op:"delAdminInfo",aid:aid},function(data){
							data=parseInt($.trim(data));
							if(data>0){
								$.messager.show({
									title:'成功提示',
									msg:'删除管理员成功...',
									timeout:3000,
									showType:'slide'
								});
								datagrid.datagrid("reload");
							}else{
								$.messager.alert('错误提示','管理员删除失败,请稍后重试...','error');
							}
						});
					}
				}
			}]   
		});
  
	});
</script>

<div id="add_admin" class="easyui-dialog" title="添加管理员" style="width:250px;height:230px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<br /><br />
	<form action="" style="float:left;padding-left:20px" id="adminInfo" name="adminInfo" method="post">
		<p><label>管理员账号：</label><input type="text" id="admin_name" name="aname"/></p>
		<br/>
		<p><label>管理员密码：</label><input type="password" id="admin_pwd" name="apwd"/></p>
		<br/>
		<p><label>请确认密码：</label><input type="password" id="twice_pwd"/></p>
		<br/>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addAdmin()" style="margin-left:60px;">添加</a>			
	</form>
</div>

<script>
	function addAdmin(){
		var aname=$("#admin_name").val();
		var apwd=$("#admin_pwd").val();
		var pwd=$("#twice_pwd").val();
		if(aname==""){
			$.messager.alert('错误提示','请输入完整的信息...','error');
			return;
		}else if(apwd==""){
			$.messager.alert('错误提示','请输入完整的信息...','error');
			return;
		}else if(pwd==""){
			$.messager.alert('错误提示','请输入完整的信息...','error');
			return;
		}else if(apwd!=pwd){
			$.messager.alert('错误提示','密码不一样...','error');
			return;
		}else{
			$.post("../adminServlet",{op:"addAdminInfo",aname:aname,apwd:apwd},function(data){
				data=parseInt($.trim(data));
				if(data>0){
					$.messager.show({
						title:'成功提示',
						msg:'添加管理员成功...',
						timeout:3000,
						showType:'slide'
					});
					$('#add_admin').dialog("close");
					$('#admin_manager').datagrid("reload");
					$("input").val(""); 
				}else{
					$.messager.alert('错误提示','管理员添加失败,请稍后重试...','error');
				}
			});
		}
	}
</script>